from pyevolve import G1DList
from pyevolve import GSimpleGA
from pyevolve import Crossovers
from pyevolve import Mutators
import pyevolve
from du import Du
from _agents import RandomAgent, MiniMaxAgent, FileAgent, AlphaBetaAgent, EvolutiveAgent
from _base import run_match
import datetime
    
def eval_func(chromosome):
    score = 0.0
    for i in xrange(100):
        result = run_match(Du(), EvolutiveAgent('MIN', 3, heuristic=Du.simple_heuristic, chromosome=chromosome), AlphaBetaAgent('MAY', 3, heuristic=Du.simple_heuristic))
        if result[0]['min'] == 1:
            score = score + 1
    return score


print datetime.datetime.now()
print "3-3-DListMutatorRealRange"
print "inicio"

# Genome instance
genome = G1DList.G1DList(4)
genome.setParams(rangemin=0, rangemax=1000)

# The evaluator function (objective function)
genome.evaluator.set(eval_func)
genome.mutator.set(Mutators.G1DListMutatorRealRange)
#gausian
#swap
#flip
ga = GSimpleGA.GSimpleGA(genome)
ga.setPopulationSize(100)
ga.setGenerations(100)

# Do the evolution, with stats dump
# frequency of 10 generations
ga.evolve(freq_stats=10)

# Best individual
print ga.bestIndividual()

print "fin"
print datetime.datetime.now()
